<html>
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
     <style type="text/css">
            @import "../dojo/dojo-release-1.0.0/dijit/themes/tundra/tundra.css";
            @import "../dojo/dojo-release-1.0.0/dojo/resources/dojo.css";
            @import "../dojo/dojo-release-1.0.0/dojox/grid/_grid/tundraGrid.css";
            @import "../dojo/dojo-release-1.0.0/dojox/grid/_grid/Grid.css";
            @import "../js/wlProject.css";
	
      </style>
      <script type="text/javascript" src="../dojo/dojo-release-1.0.0/dojo/dojo.js"  
                djConfig="parseOnLoad: true, isDebug: true,locale: 'zh-cn', extraLocale: ['zh-TW', 'fr']"></script>
      <script>
    
            dojo.require("dojo.data.ItemFileWriteStore");
            dojo.require("dijit.layout.SplitContainer");
            dojo.require("dijit.layout.ContentPane");
            dojo.require("dijit.Tree");
            dojo.require("dojo.parser");
            dojo.require("dijit._tree.dndSource");
            dojo.require("dijit.layout.TabContainer");
            dojo.require("dijit.form.Button");
            dojo.require("dojox.grid.Grid");
            dojo.require("dojox.grid._data.model");
            dojo.require("dojo.i18n");
            dojo.require("dojox.validate._base");
            dojo.require("dijit.form.ValidationTextBox");
            dojo.require("dijit.form.TextBox");
            dojo.require("dijit.form.FilteringSelect");
            dojo.require("dojox.grid._data.dijitEditors");
            
            dojo.registerModulePath("mydojo", "../../../js/mydojo");
            dojo.require("mydojo.FilteringSelect");
            dojo.require("mydojo.ValidationTextBox");
            
     </script>
        
     <script type="text/javascript" src="../js/soapclient.js"></script>
     <script type="text/javascript" src="../js/wlProject.js"></script>
     <script type="text/javascript" >
          var url= getUrl()+ "services/OrgaPeopleManageService";
          var selectNode=null;
          var selectNodeIdentity = 0;
          var griddata =  new Array();
          var deletedata=new Array();
          var querydata =  new Array();
          formatDate = function(inDatum){
                                  		  if(Boolean(dojo.date.locale.parse(thisCell[inDatum], {selector: 'date', datePattern: "YYYY.MM.DD"}))){return dojo.date.locale.format(new Date(inDatum),this.constraint);
                                         }else{return '<span style={color:red;line-height:16px}>can not be null</span>';}
                                  		}
          var model = new dojox.grid.data.Table(null, griddata);
          model.observer(this);
          modelDatumChange = function(a1, a2, a3){
		  dojo.byId("rowCount").innerHTML = ''; 
		/*	alert(a2);
			alert(a3);*/
		}
          
          
          var layout =[{type: 'dojox.GridRowView', width: '20px' },{
                       
             cells: [
                      [
                       { name: 'choise', width: 3, styles: 'text-align: center;', editor: dojox.grid.editors.Bool },//
                       { name: 'No.', width: 2, styles: 'text-align: center;', get: function(inRowIndex){ return inRowIndex+1;} },//
                        //   {name: 'orgaSno', field: 2,width: 20, editor: mydojo.ValidationTextBox ,required:true ,maxLength:30,invalidMessage:'can not be empty'}
                           {name: 'orgaName', field: 3,width: 25, editor: mydojo.ValidationTextBox ,required:true ,maxLength:30,invalidMessage:'can not be empty'}
                         ,   {name: 'orgaCode', field: 4,width: 10, editor: mydojo.ValidationTextBox , required:false ,maxLength:100,invalidMessage:'' }
                         ,   {name: 'remark', field: 5,width: 30, editor: mydojo.ValidationTextBox , required:false ,maxLength:100,invalidMessage:'' }
                         //,   {name: 'orgaState', field: 6,width: 20, editor: mydojo.ValidationTextBox ,required:true ,maxLength:30,invalidMessage:'can not be empty'}

                         ]
                     ]
                          }];
                                                                    
       function call_funUpd() {
   
           var s = grid.selection.getSelected();
           for(var i=0;i<s.length;i++){
             var ii=s[i];
             var thisCell=grid.model.data[ii];
             var padd = new SOAPClientParameters2();
             var vobject=new Object();
             vobject.id=thisCell[1];
             vobject.orgaSno=selectNodeIdentity;
             /*if(dojox.validate.isText(thisCell[2], {minlength: 1})){vobject.orgaSno=thisCell[2];
             }else{grid.getCell(ii).getNode(2).innerHTML="<p style={color:red}>can not be null</p>"; continue;}//not null*/
             if(dojox.validate.isText(thisCell[3], {minlength: 1})){vobject.orgaName=thisCell[3];
             
             }else{grid.getCell(2).getNode(ii).innerHTML="<span style={color:red;line-height:16px}>can not be null</span>";  continue;}//not null
             vobject.orgaCode=thisCell[4];
             //}else{continue;}//nullable
             vobject.remark=thisCell[5];
             //}else{continue;}//nullable
             vobject.orgaState=0;
             /*if(dojox.validate.isText(thisCell[6], {minlength: 1})){vobject.orgaState=thisCell[6];
             }else{grid.getCell(ii).getNode(6).innerHTML="<p style={color:red}>can not be null</p>"; continue;}//not null*/
             if(thisCell[1]==0){//create new row
                padd.add('OrgaInfoVO',vobject);
                SOAPClient.invoke(url, "createOrgaInfo", padd, false,  function GetEnu_callBack(ul, soapResponse){
                grid.model.setDatum(ul,i,1);
                addTreeNode(selectNode,vobject.orgaName,vobject.orgaSno,ul);
                });
	         }else{//modify row
                padd.add('OrgaInfoVO',vobject);
                SOAPClient.invoke(url, "updateOrgaInfo", padd, false,  function GetEnu_callBack(ul, soapResponse){
                setTreeNode(vobject.id,vobject.orgaName,vobject.orgaSno);
                });
	         }
          }
//submit delete
          for(var i=0;i<deletedata.length;i++){
               var pdel = new SOAPClientParameters();      
               pdel.add('id',deletedata[i]);
               SOAPClient.invoke(url, "deleteOrgaInfo", pdel, false,  function GetEnu_callBack(ul, soapResponse){
	            delTreeNode(deletedata[i]);  
	           });
          }
          deletedata=new Array();
          dojo.byId("rowCount").innerHTML = 'saved'; 
   }

 function removeSelectedRows(){
           var s = grid.selection.getSelected();
           for(var i=0;i<s.length;i++){ 
             var ii=s[i];
             var thisCell=grid.model.data[ii];
             if(thisCell[1]!=0){//the row which will be deleted
               deletedata.splice(deletedata.length,0,thisCell[1]);
             }
           }    
           grid.removeSelectedRows();
     }   
addRow = function(){
          	grid.addRow([false,0,"","","","",""],grid.model.getRowCount());
	        } 
   
//query
         
function querybutton(){
              var p = new SOAPClientParameters2();
              var queryvo=new Object();
              queryvo.id=0 ;
		    queryvo.orgaSno= '%';//
		    queryvo.orgaName= '%'+queryorgaName.getDisplayedValue()+'%';//
		    queryvo.orgaCode= '%'+queryorgaCode.getDisplayedValue()+'%';//
		    queryvo.remark= '%'+queryremark.getDisplayedValue()+'%';//
		    queryvo.orgaState= '%';//
           p.add('orgaSno','%') ;
           p.add('orgaName',queryvo.orgaName) ;
           p.add('orgaCode',queryvo.orgaCode) ;
           p.add('remark',queryvo.remark) ;
           p.add('orgaState','%') ;
           p.add('id',0) ;
              SOAPClient.invoke(url, "getOrgaInfoVO", p, false,  function GetEnu_callBack(ul, soapResponse){   
                     querydata=new Array();        
                     for(var i = 0; i < ul.length; i++){		
                      var items = new Array();
                      var ulo=ul[i];
                        items[0] = false;
                        items[1] = ulo["ns:id"];
                        items[2] = ulo["ns:orgaSno"];//
                        items[3] = ulo["ns:orgaName"];//
                        items[4] = ulo["ns:orgaCode"];//
                        items[5] = ulo["ns:remark"];//
                        items[6] = ulo["ns:orgaState"];//
                      querydata[i]=items;
                    }                
                });       
                model.setData(querydata); 
         }

   var data =new Array();
   var poptarts ={ label:'name',identifier:'eId',items:data};
   var popStore = new dojo.data.ItemFileWriteStore({data: poptarts});        
   function init(){
         
          /* dojo.connect(endgrid, "doStartEdit", function(inCell, inRowIndex){
           
            });  
            
            //单击查询列表里的记录，可选中树中的相应节点
	       dojo.connect(endgrid, "onRowClick", function(e){
	               
	        });  
        */
                     
         
         
//添加分类第一层结点
                
           //var url = getUrl()+ "services/CodeProductManageService";
           var pl = new SOAPClientParameters();
           //pl.add('eType','区域') ;
           pl.add('orgaSno','0') ;
           pl.add('orgaName','%') ;
           pl.add('orgaCode','%') ;
           pl.add('remark','%') ;
           pl.add('orgaState','%') ;
            pl.add('id',0) ;
           SOAPClient.invoke(url, "getOrgaInfoVO", pl, false,  function GetEnu_callBack(ul, soapResponse){
             var pInfo = {
                   					parent: null,		
                   					attribute: "children"	
                   		 };
                		 
                   		//alert(ul.length);
               for(var i = 0; i < ul.length; i++){		
                            var ulo=ul[i];
                            popStore.newItem({name: ulo["ns:orgaName"],type:ulo["ns:orgaSno"] ,eId:ulo["ns:id"]}, pInfo);
                            var items = new Array();
                            items[0] = false;
                            items[1] = ulo["ns:id"];
                            items[2] = ulo["ns:orgaSno"];
	                        items[3] = ulo["ns:orgaName"];
	                        items[4] = ulo["ns:orgaCode"];
	                        items[5] = ulo["ns:remark"];
	                        items[6] = ulo["ns:orgaState"];
                             griddata[i]=items;
                       }
          });
             model.setData(griddata);          
                      
//添加第二三层结点;
          var chitem;
          var chdata =new Array();
          var _tree=dijit.byId("tree");
          var childrenArray1=_tree.getChildren();
          //cityidSelectData.splice(citySelectArray.length,0,{name:'',label:'',id:0});
          for (var i=0; i<childrenArray1.length; i++){ //begin	
              var p2 = new SOAPClientParameters();
              var chNode =childrenArray1[i];
              chitem=chNode.item;
              var p2Info = {	parent: chitem,		
	                    attribute: "children"	
	                 };
	         
	       p2.add('orgaSno',chitem.eId) ;
           p2.add('orgaName','%') ;
           p2.add('orgaCode','%') ;
           p2.add('remark','%') ;
           p2.add('orgaState','%') ;
           p2.add('id',0) ;
           SOAPClient.invoke(url, "getOrgaInfoVO", p2 ,false,  function GetEnu_callBack(ul1, soapResponse){  
             for(var ii = 0; ii < ul1.length; ii++){	   
                              var ulo=ul1[ii];
                        //---
              	         var items = new Array();
                           items[0] = false;
                           items[1] = ulo["ns:id"];
                          /* items[2] = ulo["ns:orgaName"];
                           items[3] = ulo["ns:orgaCode"];
                           items[4] = ulo["ns:remark"];
                           items[1] = ulo["ns:id"];*/
	                        items[2] = ulo["ns:orgaSno"];
	                        items[3] = ulo["ns:orgaName"];
	                        items[4] = ulo["ns:orgaCode"];
	                        items[5] = ulo["ns:remark"];
	                        items[6] = ulo["ns:orgaState"];
                         //griddata[ii]=items;
                         //model.setData(griddata); 
              	        //---
           var newItemCity=	popStore.newItem({name: ulo["ns:orgaName"],type:ulo["ns:orgaSno"] ,eId:ulo["ns:id"]}, p2Info);
                              //------
                                   var p3 = new SOAPClientParameters();
                                   var p3Info = {
                                                  parent: newItemCity,		
                                                  attribute: "children"	
                                                 };
                                   p3.add('orgaSno',ulo["ns:id"]) ;
                                   p3.add('orgaName','%') ;
                                   p3.add('orgaCode','%') ;
                                   p3.add('remark','%') ;
                                   p3.add('orgaState','%') ;
                                   p3.add('id',0) ;
                                   SOAPClient.invoke(url, "getOrgaInfoVO", p3 ,false,  function GetEnu_callBack(ul2, soapResponse){  
                                   for(var j = 0; j < ul2.length; j++){
                                          var uloo=ul2[j];		
                                          popStore.newItem( {name: uloo["ns:orgaName"],type:uloo["ns:orgaSno"] ,eId:uloo["ns:id"]}, p3Info);
                                  }});
                           ///----------
                 }
            });
           _tree._expandNode(chNode);
        
         }
                
                
//初始化列表----begin
//初始化列表----end
            
//查询列表----begin
             dojo.connect(_tree, "onClick", function(item,node){
             //判断哪个tab在显示             	      
                    selectNode=node;
                    selectNodeIdentity = _tree.store.getIdentity(item);
                    var p0 = new SOAPClientParameters();
                    griddata = new Array();
                    p0.add('orgaSno',item["eId"]);
                    p0.add('orgaName','%') ;
                    p0.add('orgaCode','%') ;
                    p0.add('remark','%') ;
                    p0.add('orgaState','%') ;
                    p0.add('id',0) ;
                    SOAPClient.invoke(url, "getOrgaInfoVO", p0, false,  function GetEnu_callBack(ul, soapResponse){   
                    for(var i = 0; i < ul.length; i++){		
                      var items = new Array();
                      var ulo=ul[i];
                     items[0] = false;
                    items[1] = ulo["ns:id"];
                    items[2] = ulo["ns:orgaSno"];//
                    items[3] = ulo["ns:orgaName"];//
                    items[4] = ulo["ns:orgaCode"];//
                    items[5] = ulo["ns:remark"];//
                    items[6] = ulo["ns:orgaState"];//
                     griddata[i]=items;
                    }                
                });       
                model.setData(griddata);
                grid.selection.clear();
                deletedata =new Array();
                
             
           });  
           //查询列表----end
  }//END INIT
            
           dojo.addOnLoad(init);
           

function addTreeNode(pid,Name,Type,id){
               if(pid!=null){
               var pInfo = {
                        					parent: pid.item,		
                        					attribute: "children"	
                        				};
               }else{
               var pInfo = {
                        					parent: null,		
                        					attribute: "children"	
                        				};         				
                        				}
               popStore.newItem({name: Name,type:Type ,eId:id}, pInfo);
              
         }  
         
         
function delTreeNode(id){
               	var node = dijit.byId("tree")._itemNodeMap[id];
                popStore.deleteItem(node.item);//同时删除所有子节点
              }  
              
function setTreeNode(id,Name,Type){
               	var node = dijit.byId("tree")._itemNodeMap[id];
               	popStore.setValue(node.item,"name",Name);         
                popStore.setValue(node.item,"type",Type);      
                node.setLabelNode(Name);
                 }          
             
</script>
</head>
<body class="tundra">
       
	
	 <div dojoType="dijit.layout.SplitContainer"   orientation="horizontal"  sizerWidth="7" activeSizing="false"	style="border: 1px solid #bfbfbf; width: 1260px; height: 845px;"  >
		
         <div dojoType="dijit.layout.ContentPane" id="treePane"  sizeMin="20" sizeShare="20"   >
                     
                <div id="tree"  class="container" dojoType="dijit.Tree" persist="false" store="popStore" labelAttr="name"  childrenAttr="children"  ></div> 
         </div>
         
        <div dojoType="dijit.layout.ContentPane" sizeMin="50" sizeShare="50"  >
        
        	<div id="queryDiv" style="margin-right: 30px;  height: 23%; display:none;" >
	                        <table align="center" width=86% class="queryTable"  >
	                        <tr height="3" ></tr>
						          <tr align="center"><td >Please input criterial:</td><td></td></tr> <tr height="6" ></tr>
                                <tr align="center" >
                                
                                  <td align="right" >orgaName:</td><td align="left" ><input type="text"  jsId="queryorgaName"   dojoType="dijit.form.TextBox"  /></td>
                                  
                                  <td align="right" >orgaCode:</td><td align="left" ><input type="text"  jsId="queryorgaCode"   dojoType="dijit.form.TextBox"  /></td>
					            </tr>
                                  <tr height="6" ></tr>
                     <tr align="center" >
                                  
                                  <td align="right" >remark:</td><td align="left" ><input type="text"  jsId="queryremark"   dojoType="dijit.form.TextBox"  /></td>
					          </tr>
                                  <!--tr height="6" ></tr>
    
                                  <td align="right" >orgaState:</td><td align="left" ><input type="text"  jsId="queryorgaState"   dojoType="dijit.form.TextBox"  /></td>
					          </tr-->
                                  <tr height="6" ></tr>
	
                                  <tr align="center"><td></td><td ><a onclick="querybutton();"><img src="../image/332.gif" height="20" width="20" border="0">OK</a></td></tr> <tr height="6" ></tr>
						    </table>
	     </div>
	       	<div align="right">
	          		<a onclick="querydisplay();"><img src="../image/332.gif" height="20" width="20" border="0">query</a>
			        <a onclick="addRow();"><img src="../image/371.gif" height="20" width="20" border="0">add</a>
			        <a onclick="removeSelectedRows();"><img src="../image/808.gif" height="20" width="20" border="0">delete</a>
			        <a onclick="call_funUpd();"><img src="../image/334.gif" height="20" width="20" border="0">save</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
			     </div>   
	        
	      
	         <div id="rowCount"></div>
	   
	         <div id="grid"  dojoType="dojox.Grid" autoWidth="false" style="{height:90%;width:100%}"  jsId="grid"	model="model"  structure="layout" singleClickEdit="true" ></div>
	      </div>
      </div> 
      
</body></html>
